<template>
    <layout-ug>
        <div class="list-block">
            <ul>
                <li>
                    <div class="item-content">
                        <div class="item-media"><i class="icon icon-form-name"></i></div>
                        <div class="item-inner">
                            <div class="item-title label">账号</div>
                            <div class="item-input">
                                <input type="text" placeholder="13799999999" v-model="username">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-media"><i class="icon icon-form-password"></i></div>
                        <div class="item-inner">
                            <div class="item-title label">密码</div>
                            <div class="item-input">
                                <input type="password" placeholder="Password" class="" v-model="password">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-media"><i class="icon icon-form-password"></i></div>
                        <div class="item-inner">
                            <div class="item-title label">重复密码</div>
                            <div class="item-input">
                                <input type="password" placeholder="Password" class="" v-model="re_password">
                            </div>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
        <div class="content-block">
            <div class="row">
                <div class="col-50"><a href="/#/" class="button button-big button-fill button-danger">取消</a></div>
                <div class="col-50"><a @click.prevent="submit" class="button button-big button-fill button-success">提交</a></div>
            </div>
        </div>
    </layout-ug>
</template>

<script>
    import LayoutUg from '../layout/LayoutUg.vue'
    import axios from 'axios'

    export default{
        name: 'Reg',
        components:{
            LayoutUg
        },
        data(){
            return {
                username: '',
                password: '',
                re_password: ''
            }
        },
        methods:{
            submit(){
                if(!this.re_password || this.re_password !== this.password){
                    $.toast('Err password');
                }
                else{
                    var _this = this;
                    var u = process.env.HOST_URL + '/user/register/doRegister1';
                    axios({
                        method: 'post',
                        url: u,
                        headers: {'X-Requested-With': 'XMLHttpRequest'},
                        params: {"username":this.username, "password":this.password}
                    }).then(function(res){
                        res = res.data;
                        //console.log(res);return;
                        if(typeof res.code === 'undefined'){
                            console.log(res);return;
                        }
                        if(0 === res.code){
                            $.toast(res.msg);return;
                        }
                        $.showPreloader(res.msg);
                        sessionStorage.setItem('user', JSON.stringify(res.data));
                        setTimeout(function () {
                            $.hidePreloader();
                            _this.$router.push({name: 'Index'});
                        }, 1000);
                    })

                }

            },
            backto(){

            }
        }
    }
</script>
